//package com.tmall.wireless.tangram.example;
//
//import android.content.Context;
//import android.graphics.Bitmap;
//import android.graphics.drawable.Drawable;
//import android.support.annotation.NonNull;
//import android.support.annotation.Nullable;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//
//import com.bumptech.glide.Glide;
//import com.bumptech.glide.Priority;
//import com.bumptech.glide.load.DataSource;
//import com.bumptech.glide.load.engine.DiskCacheStrategy;
//import com.bumptech.glide.load.engine.GlideException;
//import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
//import com.bumptech.glide.request.RequestListener;
//import com.bumptech.glide.request.RequestOptions;
//import com.bumptech.glide.request.target.SimpleTarget;
//import com.bumptech.glide.request.target.Target;
//import com.bumptech.glide.request.transition.Transition;
//
//
///**
// * Created by Administrator on 2017/8/29 0029.
// */
//
//public class GlideImageLoader {
//    private static GlideImageLoader instance = null;
//
//    public static synchronized GlideImageLoader getInstance() {
//        if (instance == null) {
//            synchronized (GlideImageLoader.class) {
//                if (instance == null) {
//                    instance = new GlideImageLoader();
//                }
//            }
//        }
//        return instance;
//    }
//
//    public void displayImageRound(Context context, Object path, final ImageView imageView){
//        RequestOptions options = new RequestOptions().bitmapTransform(new RoundedCorners(10)).placeholder(R.mipmap.icon_stub)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(context).load(path.toString()).apply(options).into(imageView);
//
//    }
//
//    public void displayImageRound(Context context, Object path, int radius, final ImageView imageView){
//        RequestOptions options = new RequestOptions().bitmapTransform(new RoundedCorners(radius)).placeholder(R.mipmap.icon_stub)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(context).load(path).apply(options).into(imageView);
//
//    }
//    public void displayHeaderImage(Context context, Object path, final ImageView imageView) {
//        RequestOptions options = new RequestOptions().placeholder(R.mipmap.ic_default_header_img)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        String url = path.toString().contains("http") || path.toString().contains("https") ? path.toString():Constant.SERVER_IMAGE_URL+path.toString();
//        Glide.with(context).load(url).apply(options).into(imageView);
//
//
//    }
//
//
//    public void displayImageRound(Context context, Integer path, final ImageView imageView){
//        RequestOptions options = new RequestOptions().bitmapTransform(new RoundedCorners(10)).placeholder(R.mipmap.icon_stub)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(context).load(path).apply(options).into(imageView);
//    }
//    public void displayImageContentRound(Context context, Object path, final ImageView imageView) {
//        RequestOptions options = new RequestOptions().bitmapTransform(new RoundedCorners(30)).placeholder(R.mipmap.icon_stub)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(context).load(path.toString()).apply(options).listener(new RequestListener<Drawable>() {
//            @Override
//            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//                return false;
//            }
//
//            @Override
//            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                if (imageView == null) {
//                    return false;
//                }
//                ViewGroup.LayoutParams params = imageView.getLayoutParams();
//                int vw = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
//                float scale = (float) vw / (float) resource.getIntrinsicWidth();
//                int vh = Math.round(resource.getIntrinsicHeight() * scale);
//                params.height = vh + imageView.getPaddingTop() + imageView.getPaddingBottom();
//                imageView.setLayoutParams(params);
//                return false;
//            }
//        }).into(imageView);
//
//
//    }
//
//
//    public   void displayImageContent1(final Context context, final Object path, final ImageView imageView) {
//        final String url = path.toString().contains("http") || path.toString().contains("https") ? path.toString():Constant.SERVER_IMAGE_URL+path.toString();
//        Glide.with(context).asBitmap().load(url).into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
//            @Override
//            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//                int imageWidth = resource.getWidth();
//                int imageHeight = resource.getHeight();
//                ViewGroup.LayoutParams para = imageView.getLayoutParams();
//
//
//                int maxHeight = DensityUtil.dp2px( 3000);
//                int height = (int) ((float) imageView.getWidth()/imageWidth * imageHeight);
//                if (height > maxHeight) height = maxHeight;
//                para.height = height;
//                imageView.setLayoutParams(para);
//                Glide.with(context).asBitmap().load(url).into(imageView);
//            }
//
//        });
//
//
//
//    }
//    public void displayImageContent(Context context, Object path, final ImageView imageView) {
//            RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_stub)
//                    .priority(Priority.HIGH)
//                    .diskCacheStrategy(DiskCacheStrategy.ALL);
//        String url = path.toString().contains("http") || path.toString().contains("https") ? path.toString():Constant.SERVER_IMAGE_URL+path.toString();
//            Glide.with(context).load(url).apply(options).listener(new RequestListener<Drawable>() {
//                @Override
//                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//                    return false;
//                }
//
//                @Override
//                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                    if (imageView == null) {
//                        return false;
//                    }
//                    //获取原图的宽高
//                    int width = resource.getIntrinsicWidth();
//                    int height = resource.getIntrinsicHeight();
//
//                    //获取imageView的宽
//                    int imageViewWidth = imageView.getWidth();
//
//                    //计算缩放比例
//                    float sy = (float) (imageViewWidth * 0.1) / (float) (width * 0.1);
//
//                    //计算图片等比例放大后的高
//                    int imageViewHeight = (int) (height * sy);
//                    ViewGroup.LayoutParams params = imageView.getLayoutParams();
//                    params.height = imageViewHeight;
//                    imageView.setLayoutParams(params);
//                    return false;
//                }
//            }).into(imageView);
//
//
//
//    }
//    public void displayImageGif(Context context, Object path, ImageView imageView) {
//        RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_stub)
//                .priority(Priority.HIGH)
//                .diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(context).asGif().load(path.toString()).apply(options).into(imageView);
//    }
//
//}
